<template>
  <el-dialog
    v-model="dialogVisible"
    title="下辅操"
    width="1000px"
    @close="closeDialog"
  >
    <el-table
      :data="equipData.equipmentFuzhus"
      :highlight-current-row="true"
      size="small"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column label="序号" type="index" width="80" />
      <el-table-column label="人员编码" prop="userId" />
      <el-table-column label="人员名称" prop="fuUserName" />
      <el-table-column label="上机时间" prop="updateTime" />
      <el-table-column label="操作" min-width="120">
        <template #default="scope">
          <el-button link size="small" type="primary" @click="xiaji(scope.row)">
            下机
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup>
  import { xiaFuzhuApi } from '@/api/equip/equip_api'
  const $baseLoading = inject('$baseLoading')
  const $baseMessage = inject('$baseMessage')

  const dialogVisible = ref(false)

  const equipData = ref()

  const openDialog = async (value) => {
    dialogVisible.value = true
    equipData.value = value
  }

  const xiaji = async (value) => {
    const load = $baseLoading()
    try {
      const { code, msg } = await xiaFuzhuApi(value)
      if (code === 2000) {
        $baseMessage(msg, 'success')
        _emit('success-callback')
        dialogVisible.value = false
      } else {
        $baseMessage(msg, 'error')
      }
    } finally {
      load.close()
    }
  }

  defineExpose({ openDialog })
  const _emit = defineEmits(['success-callback'])
</script>
